﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StockPurchase.aspx.cs" Inherits="Manageweb_Stock_StockPurchase" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="Stylesheet" href="../images/css.css" />
    <link href="../Css/main.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .grid
        {
            margin: 0 auto;
        }
        #memberstocklist div
        {
            border: 0px;
            margin: 0;
            padding: 0;
        }
        .usual
        {
            background: #fff;
            color: #111;
            padding: 15px 20px;
            width: 320px;
            margin: 8px auto;
        }
        .IID
        {
            display: none;
        }
    </style>

    <script src="../Jquery/jquery-latest.min.js" type="text/javascript"></script>

    <script src="../Jquery/jquery.idTabs.min.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript">
        var memStockList;
        var boardID;
        var txtStockCode;
        var txtStockName;
        var txtStockPrice;
        var txtStockCount;
        var txtCost;
        var hidMemStockCode;
        var btnBindMemStock;
        var JYType;
        var memCode;
        var recordID;

        $(function() {
            boardID = '<%=this.GV_StockInfoList.ClientID %>';

            txtStockCode = '<%=txtStockCode.ClientID %>';
            txtStockName = '<%=txtStockName.ClientID %>';
            txtStockPrice = '<%=txtPrice.ClientID %>';

            txtStockCount = '<%=txtCount.ClientID %>';
            txtCost = '<%=txtCost.ClientID %>';
            hidMemStockCode = '<%=hidMemStockCode.ClientID %>';
            btnBindMemStock = '<%=btnBindMemStock.ClientID %>';
            memStockList = '<%=GV_MemStock.ClientID %>';

            JYType = '<%=hidJYType.ClientID %>';
            memCode = '<%=hidMemID.ClientID %>';
            recordID = '<%=hidRecordID.ClientID %>';

            $('#' + txtStockCount).keypress(function() {
                return event.keyCode >= 48 && event.keyCode <= 57;

            });

            $('#' + txtStockCount).keyup(function() {

                var countValue = $(this).val();

                if (countValue == '') {
                    return;
                }

                var regex = /^[0-9]*[1-9][0-9]*$/i;

                if (!regex.test(countValue)) {

                    return;
                }

                var price = parseFloat($('#' + txtStockPrice).val());
                var count = parseInt($('#' + txtStockCount).val());
                $('#' + txtCost).val(price * count);

            });


            $('#' + boardID + " a ").click(function() {

                var tds = $(this).parents('tr').children('td');

                $('#' + txtStockCode).val(tds[1].innerHTML);
                $('#' + txtStockName).val(tds[0].innerHTML);
                $('#' + txtStockPrice).val(tds[2].innerHTML);
                $('#' + hidMemStockCode).val(tds[1].innerHTML);
                $('#' + btnBindMemStock).click();
                $('#' + txtCost).val("");
                $('#' + txtStockCount).val("");

                $('#' + JYType).val("dapan");
            });
        });


        function test() {


            $('#' + txtStockCode).val(arguments[1]);
            $('#' + txtStockName).val(arguments[0]);
            $('#' + txtStockPrice).val(arguments[2]);
            $('#' + memCode).val(arguments[4]);
            $('#' + recordID).val(arguments[5]);
            alert(arguments[5]);
            $('#' + txtCost).val("");
            $('#' + txtStockCount).val("");
            $('#' + JYType).val("member");

        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="margin: 0 auto; padding-top: 18px">
        <asp:GridView ID="GV_StockInfoList" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" CellPadding="4" DataKeyNames="StockCode" ForeColor="#333333"
            PageSize="15" Width="720px" EmptyDataText="暂无数据" OnPageIndexChanging="GV_StockInfoList_PageIndexChanging"
            CssClass="grid">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="StockName" HeaderText="名称" SortExpression="StockName" />
                <asp:BoundField DataField="StockCode" HeaderText="编号" InsertVisible="False" ReadOnly="True"
                    SortExpression="StockCode" />
                <asp:BoundField DataField="CMoney" HeaderText="最新价" SortExpression="CMoney" />
                <asp:BoundField DataField="count" HeaderText="数量" />
                <asp:TemplateField HeaderText="操作">
                    <ItemTemplate>
                        <a href="#" name="operate">买入</a>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </div>
    <br />
    <table style="margin: 0 auto">
        <tr>
            <td>
                <div id="usual1" class="usual">
                    <ul>
                        <li><a style="font-size: 13px;" href="#tab1">股票购买</a> </li>
                    </ul>
                    <div id="tab1">
                        <table width="100%">
                            <tr>
                                <td style="width: 78px">
                                    股票代码
                                </td>
                                <td>
                                    <asp:TextBox ID="txtStockCode" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    股票名称
                                </td>
                                <td>
                                    <asp:TextBox ID="txtStockName" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    购买价格
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPrice" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    购买数量(股)
                                </td>
                                <td>
                                    <asp:TextBox ID="txtCount" runat="server" onpaste="return false;" ondragenter="return false;"
                                        Width="80px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
                                        ControlToValidate="txtCount" Display="Dynamic" SetFocusOnError="True" ValidationGroup="purchase"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="必须为正整数"
                                        SetFocusOnError="True" ControlToValidate="txtCount" Display="Dynamic" ValidationExpression="^[0-9]*[1-9][0-9]*$"
                                        ValidationGroup="purchase"></asp:RegularExpressionValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    购买金额(元)
                                </td>
                                <td>
                                    <asp:TextBox ID="txtCost" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                    <asp:Button ID="btnOK" runat="server" Text="确认购买" OnClick="btnOK_Click" ValidationGroup="purchase" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                </td>
                            </tr>
                        </table>
                        <asp:Label ID="lblMsg" runat="server"></asp:Label>
                    </div>
                </div>
            </td>
            <td style="vertical-align: top;">
                <div id="memberstock" class="usual">
                    <ul>
                        <li><a style="font-size: 13px;" href="#tab1">会员股票</a> </li>
                    </ul>
                    <div id="memberstocklist">
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>
                                <asp:GridView ID="GV_MemStock" runat="server" AutoGenerateColumns="False" Width="300px"
                                    EmptyDataText="没有会员卖出该股票" OnRowDataBound="GV_MemStock_RowDataBound">
                                    <Columns>
                                        <asp:BoundField DataField="stockname" HeaderText="名称" />
                                        <asp:BoundField DataField="stockcode" HeaderText="代码" />
                                        <asp:BoundField DataField="cmoney" HeaderText="价格" />
                                        <asp:BoundField DataField="count" HeaderText="数量" />
                                        <asp:BoundField DataField="userid" HeaderText="会员" />
                                        <asp:BoundField DataField="iid" HeaderText="id">
                                            <ItemStyle CssClass="IID" />
                                        </asp:BoundField>
                                    </Columns>
                                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                </asp:GridView>
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="btnBindMemStock" EventName="Click" />
                            </Triggers>
                        </asp:UpdatePanel>
                    </div>
                </div>
            </td>
        </tr>
    </table>

    <script type="text/javascript">        $("#usual1 ul").idTabs(); </script>

    <asp:Button ID="btnBindMemStock" runat="server" Height="20px" OnClick="btnBindMemStock_Click"
        CssClass="IID" Text="Button" />
    <asp:HiddenField ID="hidMemStockCode" runat="server" />
    <asp:HiddenField ID="hidJYType" runat="server" />
    <asp:HiddenField ID="hidMemID" runat="server" />
    <br />
    <asp:HiddenField ID="hidRecordID" runat="server" />
    </form>
</body>
</html>
